module TicketsHelper
  
  def notefield (note)
    result = ""
    case note.note_type.vtype
    when "vstring"
      result += "<br /><input id='ticket_notes_attr__value' type='text' value=\'#{note.value}\' size='40' name='ticket[notes_attr][][value]' maxlength='255'>"
    when "vselect"
      result += "<select id='ticket_notes_attr__value' name='ticket[notes_attr][][value]'>" +
         options_for_select(note.note_type.choises, note.svalue) +
         "</select>"
    when "vdate"

       result += calendar_date_select_tag('ticket[notes_attr][][value]', note.value, {:id => 'ticket_notes_attr__value', :size => '10', :maxlength => '10'})   
    when "vtext"
      result += "<br /><textarea rows='5' wrap='soft' cols='40' id='ticket_notes_attr__value' type='text' value=\'#{note.value}\' size='40' name='ticket[notes_attr][][value]'>#{note.value}</textarea>"
    when "vcheckbox"
      result += "<br /> <input id='ticket_notes_attr__value' type='checkbox' "+ (note.value ? 'checked="checked"' : "" )+"  value='true' name='ticket[notes_attr][][value]'>"
    end
    result
  end

  def show_notefield(note)
    result = note.note_type.name + " "
    if note.note_type.vtype == "vcheckbox"
       result += note.bvalue? ? "Done" : "Not done"
    else
       result += "<br />" + note.value.to_s + "<br />"
    end
    result
  end

  def add_clear_field_link(name)
    link_to_function name do |page|
      page.insert_html :bottom, :clear_conditions, :partial => 'clear_conditions'
    end
  end

end
